# Makefile for Python Project Automation

.PHONY: help install install-dev test test-cov lint format clean setup

# 默认目标
help:
	@echo "可用命令:"
	@echo "  setup        - 设置开发环境"
	@echo "  install      - 安装生产依赖"
	@echo "  install-dev  - 安装开发依赖"
	@echo "  test         - 运行所有测试"
	@echo "  test-cov     - 运行测试并生成覆盖率报告"
	@echo "  lint         - 代码检查"
	@echo "  format       - 代码格式化"
	@echo "  clean        - 清理临时文件"

# 环境设置
setup:
	python3 -m venv .venv
	@echo "虚拟环境已创建，请运行: source .venv/bin/activate"

# 安装依赖
install:
	pip install -r requirements.txt

install-dev:
	pip install -r requirements-dev.txt

# 测试
TEST_PATH = tests/

# 运行所有测试
test:
	python -m pytest $(TEST_PATH) -v

# 运行测试并生成覆盖率报告
test-cov:
	python -m pytest $(TEST_PATH) --cov=api --cov-report=html --cov-report=term

# 代码质量
lint:
	flake8 api/ tests/ --max-line-length=120 --ignore=E203,W503
	mypy api/ --ignore-missing-imports

format:
	black api/ tests/ --line-length=120
	isort api/ tests/

# 清理
clean:
	find . -type d -name "__pycache__" -exec rm -rf {} +
	find . -type f -name "*.pyc" -delete
	find . -type f -name "*.pyo" -delete
	find . -type f -name "*.pyd" -delete
	find . -type f -name "*.so" -delete
	rm -rf .coverage htmlcov/ build/ dist/ *.egg-info/

# 开发服务器
dev:
	python main.py

# 生成测试数据
generate-data:
	python scripts/generate_test_data.py

# 运行端到端测试
e2e:
	python -m pytest tests/e2e/ -v

# 生成文档
docs:
	sphinx-build -b html docs/ docs/_build/